package com.activepad.module.customer.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.activepad.module.customer.dao.EnterpriseCustomerDao;
import com.activepad.module.customer.pojo.CustomerVo;
import com.common.bean.ArgumentsBean;
import com.common.enums.Symbol;

/**
 * 
 * 企业客户业务处理类
 * 
 * @author 孙树林
 * 
 */
public class EnterpriseCustomerService {

	private EnterpriseCustomerDao enterpriseCustomerDao;

	/**
	 * 
	 * 查询企业客户业务处理方法
	 * 
	 * @author 孙树林
	 * @param customerVo
	 * @return
	 */
	public List<CustomerVo> searchEnterpriseCustomer(CustomerVo customerVo) {
		List<CustomerVo> enterpriseCustomers = new ArrayList<CustomerVo>();
		
		// 不显示失效的企业客户
		ArgumentsBean argumentsBean = new ArgumentsBean();
		argumentsBean.setParamName("isEffevtive");
		argumentsBean.setParamType("string");
		argumentsBean.setSymbol(Symbol.eq.getValue());
		argumentsBean.setValues(new String[]{"130001"});
		customerVo.getArgumentsBeans().add(argumentsBean);
		
		enterpriseCustomers = enterpriseCustomerDao.searchEnterpriseCustomer(customerVo);
		return enterpriseCustomers;
	}

	/**
	 * 
	 * 查找某一企业客户资料信息
	 * 
	 * @author 孙树林
	 * @param id
	 * @return
	 */
	public CustomerVo findEnterpriseCustomer(Integer id) {
		// 客户资料
		CustomerVo vo = enterpriseCustomerDao.findEnterpriseCustomer(id);
		return vo;
	}
	
	/**
	 * 编辑企业客户资料信息
	 * 
	 * @author 孙树林
	 * @param customerVo
	 */
	public void editEnterpriseCustomer(CustomerVo customerVo) {
		Integer id = customerVo.getId();
		if(id != null) {
			enterpriseCustomerDao.updateEnterpriseCustomer(customerVo);
		} else {
			customerVo.setRegTime(new Date());
			customerVo.setCreateTime(new Date());
			customerVo.setIsEffevtive("130001");
			enterpriseCustomerDao.saveEnterpriseCustomer(customerVo);
		}
	}
	
	/**
	 * 删除企业客户信息，及相关资料信息。
	 * @param id
	 */
	public void deleteEnterpriseCustomer(CustomerVo customerVo) {
		customerVo.setIsEffevtive("130002");
		enterpriseCustomerDao.updateEnterpriseCustomer(customerVo);
	}

	public void setEnterpriseCustomerDao(EnterpriseCustomerDao enterpriseCustomerDao) {
		this.enterpriseCustomerDao = enterpriseCustomerDao;
	}
}
